<template>
    <div class="system-user-container layout-padding">
        <el-card shadow="hover" class="layout-padding-auto">
            <div class="system-user-search mb15">
                <el-input size="default" v-model="state.dataForm.username" placeholder="请输入用户名称" style="max-width: 180px"></el-input>
                <el-button size="default" type="primary" class="ml10">
                    <el-icon>
                        <ele-Search/>
                    </el-icon>
                    查询
                </el-button>
                <el-button size="default" type="success" class="ml10" @click="userDialogRef.openDialog('add')">
                    <el-icon>
                        <ele-FolderAdd/>
                    </el-icon>
                    新增用户
                </el-button>
            </div>
            <el-table :data="state.dataList" v-loading="state.dataListLoading" style="width: 100%">
                <el-table-column type="index" label="序号" width="60" align="center"/>
                <el-table-column prop="username" label="账户名称" show-overflow-tooltip align="center"></el-table-column>
                <el-table-column prop="realName" label="用户姓名" show-overflow-tooltip align="center"></el-table-column>
                <el-table-column prop="roleIds" label="关联角色" show-overflow-tooltip align="center"></el-table-column>
                <el-table-column prop="deptIds" label="部门" show-overflow-tooltip align="center"></el-table-column>
                <el-table-column prop="phone" label="手机号" show-overflow-tooltip align="center"></el-table-column>
                <el-table-column prop="email" label="邮箱" show-overflow-tooltip align="center"></el-table-column>
                <el-table-column prop="lockFlag" label="用户状态" show-overflow-tooltip align="center">
                    <template #default="scope">
                        <el-tag type="success" v-if="scope.row.lockFlag">启用</el-tag>
                        <el-tag type="info" v-else>禁用</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="150" align="center">
                    <template #default="scope">
                        <el-button size="small" text type="primary"
                                   @click="userDialogRef.openDialog('edit', scope.row.userId)"
                        >修改
                        </el-button
                        >
                        <el-button :disabled="scope.row.userName === 'admin'" size="small" text type="danger"
                                   @click="state.deleteHandle(scope.row.userId)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination :current-page="state.page" :page-size="state.limit"
                           :total="state.total" layout="total, sizes, prev, pager, next, jumper"
                           class="mt15"
                           @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"/>
        </el-card>
        <UserDialog ref="userDialogRef" @refresh="state.getDataList()"/>
    </div>
</template>

<script setup lang="ts" name="systemUser">
import {defineAsyncComponent, reactive, onMounted, ref, toRefs} from 'vue';
import {ElMessageBox, ElMessage} from 'element-plus';
import UserApi from "/@/api/system/UserApi";
import ApiConfig from "/@/api/ApiConfig";
import useView from "/@/hooks/useView";

// 引入组件
const UserDialog = defineAsyncComponent(() => import('/@/views/system/user/dialog.vue'));

// 定义变量内容
const userDialogRef = ref();
const view = reactive({
    getDataListURL: ApiConfig.SYSTEM.USER_PAGE,
    getDataListIsPage: true,
    deleteURL: ApiConfig.SYSTEM.USER,
    deleteIsBatch: true,
    dataForm:{
        username:''
    },
    configVisible: false,
    uploadVisible: false
});

const state = reactive({...useView(view), ...toRefs(view)});

</script>

<style scoped lang="scss">
.system-user-container {
  :deep(.el-card__body) {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: auto;

    .el-table {
      flex: 1;
    }
  }
}
</style>
